<?php
class Pageley_Util_Pattern {
    private $pattern;
    
    public function __construct($pattern) {
        $this->pattern = $pattern;
    }
    
    public function match($text) {
        $matches = array();
        $result = preg_match($this->pattern, $text, $matches);
        if($result === false) {
            throw new Pageley_Util_IllegalArgumentException("Invalid regular expression: " . $this->pattern);
        }
        return new Pageley_Util_ArrayMap($matches);
    }
    
    public function matchAll($text) {
        $matches = array();
        $result = preg_match_all($this->pattern, $text, $matches);
        if($result === false) {
            throw new Pageley_Util_IllegalArgumentException("Invalid regular expression: " . $this->pattern);
        }
        return new Pageley_Util_ArrayMap($matches);
    }
}